package com.vitabuybuy.tv.dialog

import android.content.Context
import android.view.View
import android.view.animation.Animation
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.library.common.ext.setOnclick
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.PopupAllLimitedGroupBinding
import com.vitabuybuy.tv.databinding.PopupAreaCodeBinding
import com.vitabuybuy.tv.databinding.PopupGiftQuantityBinding
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.ScaleConfig
import razerdp.util.animation.TranslationConfig

/**
 * 删除弹出框
 */
class AreaCodePopup(
    context: Context,
    private var onConfirm: (quantyty: String) -> Unit
) : BasePopupWindow(context) {

    private lateinit var mBinding: PopupAreaCodeBinding


    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_area_code)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        mBinding = DataBindingUtil.bind<ViewDataBinding>(contentView) as PopupAreaCodeBinding
        setOnclick(
            mBinding.flChina,
            mBinding.flHongkong,
            mBinding.flMacao,
            mBinding.flTaiwan,
            mBinding.flMalaysia
        ) {
            when (it) {
                mBinding.flChina -> {
                    onConfirm.invoke("+86")
                }
                mBinding.flHongkong -> {
                    onConfirm.invoke("+852")
                }
                mBinding.flMacao -> {
                    onConfirm.invoke("+853")
                }
                mBinding.flTaiwan -> {
                    onConfirm.invoke("+886")
                }
                mBinding.flMalaysia -> {
                    onConfirm.invoke("+60")
                }
            }
            dismiss()
        }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.FROM_BOTTOM)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.TO_BOTTOM)
            .toDismiss()
    }
}